package com.heima.freemarker.controller;

import com.heima.freemarker.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.management.StandardEmitterMBean;
import java.util.*;

@Controller
public class HelloController {


    @GetMapping("/basic")
    public String hello(Model model){
        //name
        model.addAttribute("name","freemarker");
        //stu
        Student student = new Student();
        student.setAge(18);
        student.setName("小明");
        model.addAttribute("stu",student);

        return "01-basic";
    }

    @GetMapping("/list")
        public String list(Model model){

        Student stu1 = new Student();
        stu1.setName("小强");
        stu1.setAge(20);
        stu1.setMoney(1000.86f);
        stu1.setBirthday(new Date());

        //小红的对象数据
        Student stu2 = new Student();
        stu2.setName("小红");
        stu2.setAge(21);
        stu2.setMoney(200.86f);
        stu2.setBirthday(new Date());

        List<Student> stus=new ArrayList<>();
        stus.add(stu1);
        stus.add(stu2);

        model.addAttribute("stus",stus);

        Map<String,Student> stuMap=new HashMap<>();
        stuMap.put("stu1",stu1);
        stuMap.put("stu2",stu2);
        model.addAttribute("stuMap",stuMap);
        model.addAttribute("today",new Date());
        return "02-list";
        }
}

